use crypto::digest::Digest;
use crypto::sha3::Sha3;
use serde::{Deserialize, Serialize};

pub fn my_serialize<T:?Sized>(value: &T) -> Vec<u8>
where T: Serialize,
{
    let serialized=bincode::serialize(value).unwrap();
    serialized
}

pub fn my_deserialize<'a, T:?Sized>(bytes: &'a [u8]) -> T
where T: Deserialize<'a>,
{
    let deserialized= bincode::deserialize(bytes).unwrap();
    deserialized
}

pub fn get_hash(value:&[u8]) -> String {
    let mut hasher=Sha3::sha3_256();
    hasher.input(value);
    hasher.result_str()
}

// test mod
#[derive(Debug,PartialEq,Eq,Serialize,Deserialize)]
struct Point{
    x: i32,
    y: i32,
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn coders_works() {
        let point=Point{x:10,y:20};
        let se=my_serialize(&point);
        let de:Point=my_deserialize(&se);
        assert_eq!(de, point);
    }
}